package com.hangxiang.approval.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hangxiang.approval.common.ApplyPeopleInsertCommon;
import com.hangxiang.approval.common.ApplyPeopleUpdateCommon;
import com.hangxiang.approval.common.IntegerCommon;
import com.hangxiang.approval.dao.ApplyPeopleDao;
import com.hangxiang.approval.entity.ApplyPeople;
import com.hangxiang.approval.service.ApplyPeopleService;
import com.hangxiang.approval.vo.ApplyPeopleVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;


/**
 * 用户申请抄送记录表(ApplyPeople)表服务实现类
 *
 * @author makejava
 * @since 2020-11-25 16:28:48
 */
@Service("applyPeopleService")
public class ApplyPeopleServiceImpl extends ServiceImpl<ApplyPeopleDao, ApplyPeople> implements ApplyPeopleService {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Resource
    private ApplyPeopleDao applyPeopleDao;

    /**
     * 通过ID查询单条数据
     *
     * @param common 主键
     * @return 实例对象
     */
    @Override
    public ApplyPeopleVo queryById(IntegerCommon common) {
        ApplyPeopleVo vo = new ApplyPeopleVo();
        ApplyPeople applyPeople = applyPeopleDao.selectById(common.getValue());
        BeanUtils.copyProperties(applyPeople, vo);
        return vo;
    }


    /**
     * 新增数据
     *
     * @param applyPeopleInsertCommon 实例对象
     * @return 实例对象
     */
    @Override
    @Transactional
    public Integer insertApplyPeople(ApplyPeopleInsertCommon applyPeopleInsertCommon) {
        ApplyPeople applyPeople = new ApplyPeople();
        BeanUtils.copyProperties(applyPeopleInsertCommon, applyPeople);
        applyPeopleDao.insert(applyPeople);
        return applyPeople.getId();
    }

    /**
     * 修改数据
     *
     * @param applyPeopleUpdateCommon 实例对象
     * @return 实例对象
     */
    @Override
    @Transactional
    public Integer updateApplyPeople(ApplyPeopleUpdateCommon applyPeopleUpdateCommon) {
        ApplyPeople applyPeople = new ApplyPeople();
        BeanUtils.copyProperties(applyPeopleUpdateCommon, applyPeople);
        applyPeopleDao.updateById(applyPeople);
        return applyPeople.getId();
    }
}